package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@Tag(name = "商品分类管理模块")
@RequestMapping("/admin/product/category")
public class CategoryController {
    @Resource
    CategoryService categoryService;
    @Operation(summary = "导入分类excel数据接口")
    @PostMapping("import")
    public Result importCates(MultipartFile excel){
        categoryService.importCates(excel);
        return Result.ok();
    }
    @Operation(summary = "导出分类的excel文件")
    @GetMapping("export")
    public void exportCates(HttpServletResponse response){
        //下载文件：需要我们手写响应报文(response)
        categoryService.exportCates(response);
    }
    @Operation(summary = "根据pid查询下级分类列表")
    @GetMapping("listByPid/{parentId}")
    public Result listByPid(@PathVariable("parentId")Long parentId){
        List<Category> categoryList = categoryService.listByPid(parentId);
        return Result.ok(categoryList);
    }
}
